import { Inject, Injectable } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { configuration } from "../../../config/config";

@Injectable()
export class NatsClientService {
  constructor(
    @Inject(configuration.gateway.nats_client_name)
    private natsClient: ClientProxy,
  ) {}

  send(event, msg) {
    return this.natsClient.send(event, msg);
  }

  emit(event, msg) {
    console.log(`emit: ${event}, msg: ${JSON.stringify(msg)}`);
    return this.natsClient.emit(event, msg);
  }
}
